=============================================================================================================
Files: readme.txt, cleanit-functions.php, cleanit-functions.asp, ChangeLog.txt
Reference: http://www.webmastersherpa.com/content/useful-code/cleanup/
=============================================================================================================	

Please note that the asp and php versions are VERY different. The php version does all the things 
discussed on the webmasterherpa site. The asp version, written by James Crooke (www.cj-design.com)
only includes two functions, one (fckEditorFix) to convert special MS Word characters and the 
second (stripHTML) to strip all HTML from code except for tags specified in the parameter "allowedTags"

Also note that this code doesn't modify FCKeditor directly. Rather, it is used to do processing after 
submitting a form that has a FCKeditor based textarea field. In this way, you *should* be able to upgrade
to new versions of FCKeditor without having to worry about this code. 

Finally, note that there are two primary functions: tidy and cleanit. The tidy function is what cleans up 
most of the paste from word mess (font and span tags, xml, useless classes and styles, etc.). The cleanit 
function mostly handles list items and images and it actually uses the tidy function first. I'm not sure 
why you would want to use only the tidy function, but it's set up so you can.

To test this script prior to installation, see the online demo at: 
http://www.webmastersherpa.com/content/useful-code/cleanup/


===================================
=== cleanit-functions.php Usage ===
===================================

************************************
*** using the tidy function only ***
************************************
If all you want to do is tidy up the special characters and the extra spaces and tags that MS Word uses,
you can use the function called tidy:

  include("cleanit-functions.php");
  $html = tidy($html);

where $html is whatever variable you are assigning to the FCKeditor field. 


***********************************
*** using the cleanit function  ***
***********************************
Performing the complete cleanup is a bit more complicated than above. In order to track the lists, I have 
to break the output of the FCKeditor into multiple lines and handle each line separately. That's what I 
am doing below with the array variable called $lines. So, assuming your FCKeditor field is called "editor" 
the complete calling code would look like: 

  $html = stripslashes($_POST["editor"]);
  $lines = explode("\n",$html);
  $_POST["editor"] = cleanit($lines,$imagepath,$imagestartnum,$alt_prefix);


************************************
*** handling nested lists        ***
************************************
If you have nested list items it is really hard to know whether a new line belongs the higher level list 
(and thus shouldn't close that higher list) or if it signifies the end of all lists and beginning of 
regular paragraph text. To differentiate, cleanit assumes that 2 consecutive line breaks indicate that 
all lists should be closed. This isn't perfect, but I can't think of a better way to do it. 

If you have line breaks in text that is within a line item, make sure you have used a <shift>+<return> to 
accomplish that otherwise the cleanit function will think that it should end that list item...


************************************
*** handling <code></code> text  ***
************************************
All class definitions are automatically stripped by the fck_paste.html file in FCKeditor by default. So, if 
you want use the code format in MS Word (e.g., to highlight computer code) you will need to comment out the 
following line in that /dialog/fck_paste.html file: 
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;


************************************
*** Handling Images              ***
************************************
When pasting content from MS Word that contains an image, FCKeditor strips out all the xml. Unfortunately, 
the image info is contained in xml tags. So, if you want the cleanit function to handle your images, you will 
need to modify the /editor/dialog/fck_paste.html file by commenting out the following lines:
  html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;
  html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ; (NOTE: 3 consecutive instances of this line) 

In general, handling images is a real pain. The way I do it is to save the MS Word document as a html file, which 
then creates a folder with all the relevant images. I then manually FTP those to a folder on my server. If you 
want to do the same, you can tell the cleanit function where to look by specifying a path by using the $imagepath 
parameter. Also, MS Word usually saves the images in numeric order, e.g. image001.gif, image002.jpg, etc. 
If you wanted to break up processing into multiple steps, you can specify which imagenumber to start with
by using the $imagestartnum parameter. Finally, I use an alt tag like "image number 1" but you can add a prefix
to that using the $alt_prefix parameter, so for example, you could end up with "presidential election image 1"
by specifying "presidential election" as the alt_prefix. 

	   
===================================
=== cleanit-functions.asp Usage ===
===================================
<!-- #include file="cleanit-functions.asp" -->
 
' get the HTML from FCKEditor
html = request.form("html")
 
' fix html and then strip tags except allowed tags
html = stripHTML(fckEditorFix(html), "strong,b,i,em,p,br")

Then variable "html" will contain your cleaned source.